package cn.tedu;

import org.junit.Test;

import java.sql.*;

public class Demo03 {

    @Test
    public void insert() throws SQLException {
        System.out.println("insert");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","123456");
        Statement s = conn.createStatement();
        s.executeUpdate("insert into emp(name) values('Tom')");
        conn.close();
    }

 @Test
    public void select() throws SQLException {
        System.out.println("select");
     Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","123456");
     Statement s = conn.createStatement();
     ResultSet rs = s.executeQuery("select name,job,sal from emp");
     while (rs.next()){
         String name = rs.getString(1);
         String job = rs.getString(2);
         double sal = rs.getDouble(3);
         System.out.println(name+":"+job+sal);
     }
     conn.close();
    }

 @Test
    public void delete() throws SQLException {
        System.out.println("delete");
     Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","123456");
     Statement s = conn.createStatement();
     s.executeUpdate("delete from emp where name='Jerry'");
     conn.close();
    }

 @Test
    public void update() throws SQLException {
        System.out.println("update");
     Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","123456");
     Statement s = conn.createStatement();
     s.executeUpdate("update emp name set name='Jerry' where name='Tom'");
     conn.close();
    }



}
